package cn.com.connext.scrm.utils;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 实体转换工具类
 */
public class EntityUtils {
    public static <S, T> List<T> dtoList2PojoList(List<S> src, Class<?> targetClass) {
        if (CollectionUtils.isEmpty(src)) {
            return Lists.newArrayListWithCapacity(src.size());
        }
        List<T> target = Lists.newArrayListWithCapacity(src.size());
        for (S s : src) {
            try {
                Object object = targetClass.newInstance();
                BeanUtils.copyProperties(s, object);
                target.add((T) object);
            } catch (Exception e) {
                continue;//某个方法反射异常
            }
        }
        return target;
    }
}

